package com.hyzx.qbasic.admin.common.exception;

import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.NoHandlerFoundException;

/**
 * Created by 黄江华 on 2017/9/29
 */

@Controller
@ControllerAdvice
public class ErrorHandleController {

    @ExceptionHandler(UnauthorizedException.class)
    @ResponseStatus(HttpStatus.UNAUTHORIZED)
    @RequestMapping("/error/401")
    public String unauthorized() {
        return "/error/401";
    }

    @ExceptionHandler(NoHandlerFoundException.class)
    @ResponseStatus(HttpStatus.NOT_FOUND)
    @RequestMapping("/error/404")
    public String notFound() {
        return "/error/404";
    }

    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @RequestMapping("/error/400")
    public String paramError() {
        return "/error/400";
    }
}
